package com.snow.datasource.properties;

import com.snow.datasource.creator.druid.DruidProperties;
import lombok.Data;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.core.Ordered;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * 动态数据源属性配置
 *
 * @Description
 * @Author fanxl 315620726@qq.com
 * @Date 2020/12/16
 **/
@Data
@ConfigurationProperties(prefix = SnowFlakeProperties.PREFIX)
public class SnowFlakeProperties implements InitializingBean {
    public static final String PREFIX = "spring.datasource.dynamic";

    /**
     * 主数据源
     */
    private String primary;
    /**
     * 数据源类型
     */
    private String type;

    /**
     * 策略
     */
    private String strategy;
    /**
     * 加载顺序
     */
    private Integer order = Ordered.HIGHEST_PRECEDENCE;

    /**
     * aop 切面是否只允许切 public 方法
     */
    private boolean allowedPublicOnly = true;

    /**
     * 多数据源
     */
    private ConcurrentHashMap<String, DataSourceProperty> datasource;

    @NestedConfigurationProperty
    private DruidProperties druid;


    @Override
    public void afterPropertiesSet() throws Exception {
    }
}
